<!--
- Author:  LiShibin.
- Date:    2017/7/17 0017.
- File:    password.
-->
<template>
  <div class="Web_Box">
    <div @click="back" class="Topmenu"><i class="iconfont icon-youjiantou"><a href=""></a></i>
      <h1>忘记密码</h1>
      <span></span>
    </div>
    <div class="login_dl">
      <div class="login_ipt1">
        <i class="iconfont icon-denglu_shoujihao1"></i><input type="number" v-model="mobile" placeholder="输入手机号">
        <span style="width: 120px;">
          <message-code type="2" :tel="mobile"  :callback="handleMessageCode"></message-code>
        </span>
      </div>
      <div class="login_ipt1">
        <i class="iconfont icon-wangjimima_yanzhengma"></i><input type="number" v-model="code" placeholder="输入验证码">
      </div>
      <div class="login_ipt1">
        <i class="iconfont icon-wangjimima_xinmima"></i><input type="password" v-model="password" placeholder="输入新密码">
      </div>

    </div>
    <div class="login_btn1" style="padding: 3rem 10px;">
      <span @click="modifyPwd">提交</span>
    </div>
  </div>
</template>

<script>
  import messageCode from '../../components/message-code.vue'
  export default{
    data() {
      return {
        mobile: '',
        code: '',
        password: ''
      }
    },
    components: {
      'message-code': messageCode
    },
    methods: {
      back() {
        this.$router.go(-1)
      },
      handleMessageCode(code) {
        this.check_mobile = code
      },
      modifyPwd() {
        var postData = {}
        postData.mobile = this.mobile
        postData.secode = this.code
        postData.n_password = this.password
        if (!this.$validator.phone(this.mobile)) {
          this.$toast('请输入正确的手机号！')
          return
        }
        if (this.code == '') {
          this.$toast('请输入短信验证码！')
          return
        }
        if (!/^[\w]{6,12}$/.test(postData.n_password)) {
          this.$toast('请设置6-12位数字或字母密码！')
          return
        }
        this.$request.modifyPwd(postData).then(data => {
          this.$toast('密码重置成功，请重新登录！')
          this.signOut()
        }).catch(e => {
          this.$toast(e.msg)
        })
      },
      signOut() {
        this.$storage.delKey()
        this.$storage.setAuthed(false)
        this.$storage.delMemberInfo()
        this.$router.replace({name: 'login-password'})
        this.$utils.delCookie('key')
      }
    }
  }
</script>

<style>

</style>
